package com.lnsoft.cac.server.handle.codec.frameMessage;


import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import lombok.Data;
import lombok.NonNull;

@Data
/**
 * 通信流量数据报-数据流量上送报文
 * */
public class FlowData_Cfm {
    private int Command_Status;         //1byte         数据发送状态：①0xFF成功②0x00失败

    public ByteBuf toByteBuf() throws Exception{
        if (Command_Status != (byte)0xFF && Command_Status != (byte)0x00) {
            throw new Exception("数据发送状态 设置异常");
        }
        ByteBuf bf = Unpooled.buffer();
        bf.writeByte(Command_Status);
        return bf;
    }



    //  解析 [数据流量上送报文-确认] 帧报文内容区 到消息体中
    public static FlowData_Cfm decFrameBody(@NonNull byte[] frameBody) throws Exception {
        ByteBuf bf = Unpooled.wrappedBuffer(frameBody);
        FlowData_Cfm msg = new FlowData_Cfm();
        int len = frameBody.length;
        if (len == 0) {
            return null;
        }
        if (12 != len) {
            throw new Exception("frameBody 数据异常");
        }
        msg.setCommand_Status(bf.getByte(0) & 0xFF);
        return msg;
    }

}
